<?php
namespace Admin\Controller;
use Think\Controller;

/**
 * 用户管理控制器
 * Class UserController
 * @package Admin\Controller
 */
class UserController extends BaseController{

    /**
     * 添加管理员用户
     */
    public function addUser(){
        if(IS_AJAX){

	        $recommend = I('recommend');
        	$this->checkLimit($recommend);
            $User = M('Admin');
            $data = $User->create();
            $data['create_time'] = time();
            $data['password'] = md5($data['password']);
            $res = $User->add($data);
            if($res){
	            if( ! empty($recommend))
	            {
	            	$uid = $res;
		            $this->doRelation($recommend, $uid);
	            }

                //记录操作到日志
                $action_name = "添加管理员";
                $time = date("Y-m-d H:i:s", time());
                parent::rizhi($action_name, $time);

                $this->ajaxReturn(['info'=>'添加成功','status'=>1,'url'=>U('User/userList')]);
            }else{
                $this->ajaxReturn(['info'=>'添加失败','status'=>0,'url'=>U('User/addUser')]);
            }
        }else{

            $role = M('Role')->where(['status'=>0])->select();
            $this->assign("role",$role);

            $this->display();
        }
    }

}